define(function(require) {
	
	var $ = require("jquery");
	
	var backManagerService = require("bean/backManagerService");
	var utils = require("utils");
	var ctx = utils.constants.ctx;
	var ui = require("ui");
	
	$("#userApproved").bind("click",function(){
		if(window.confirm("是否通过审核?")){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userApproval(userId);
				ui.mask().hide();
				alert("审核成功");
				location.href = ctx+"/back/base/userAuditList";
			} catch(e){
				ui.mask().hide();
				alert("审核失败");
			}
		}
	});
	
	$("#userUnApproved").bind("click",function(){
		if(window.confirm("是否不通过审核?")){
			var userId = $("#user_id").val();
			if(userId == null){
				return  false ;
			}
			try {
				ui.mask().show("请稍候...");
				backManagerService.userUnApproval(userId);
				ui.mask().hide();
				alert("操作成功");
				location.href = ctx+"/back/base/userAuditList";
			} catch(e){
				ui.mask().hide();
				alert("审核失败");
			}
		}
	});
	
	$("#auditUserList").bind("click",function(){
		if ($('input[name=items]:checkbox:checked').length <= 0) {
			alert("请选择用户");
			return;
		}
		if(!window.confirm("确定这些用户通过审核？")){
			return;
		}
		var array = [];
		$('input[name=items]:checkbox:checked').each(function() {
		    	
			var id = $(this).attr("id").replace("user_", "");
			array.push(id);   
		});
		if (array.length != 0) {
			try{
				ui.mask().show("请稍候...");
				backManagerService.userApprovalList(array);
				ui.mask().hide();
				alert("审核成功");
				location.href = ctx+"/back/base/userAuditList";
			} catch (e) {
				ui.mask().hide();
				alert("审核失败:"+e.message);
			}
		} 
	});
	
	$("#searchBtn").bind("click",function(){
		var searchContent = $("#searchInfo").val();
		
		if(searchContent == null){
			alert("请输入搜索内容")
			return false ;
		}
		ui.mask().show("请稍候...");
		location.href = ctx+"/back/base/userAuditList?username="+searchContent;
		
	});
	
});